/*	
	
	Copyright (c) 2007-2009 Ryan Christiansen
	
	This software is provided 'as-is', without any express or implied
	warranty. In no event will the authors be held liable for any damages
	arising from the use of this software.
	
	Permission is granted to anyone to use this software for any purpose,
	including commercial applications, and to alter it and redistribute it
	freely, subject to the following restrictions:
	
	1. The origin of this software must not be misrepresented; you must not
	claim that you wrote the original software. If you use this software
	in a product, an acknowledgment in the product documentation would be
	appreciated but is not required.
	
	2. Altered source versions must be plainly marked as such, and must not be
	misrepresented as being the original software.
	
	3. This notice may not be removed or altered from any source
	distribution.
	
*/
package funit.framework
{
	import funit.MessageValidator;
	
	[TestFixture]
	public class StringAssertTests extends MessageValidator
	{
		
		
		public function StringAssertTests()
		{
			
		}
		
		
		[Test]
		public function isEmpty() : void
		{
			StringAssert.isEmpty( "", "Failed on empty String" );
		}
		
		[Test]
		[ExpectedError("funit.errors::AssertionError")]
		public function isEmptyFailureOnString() : void
		{
			expectedMessage =
				MessageString.ExpectedPrefix + "<empty>" + MessageString.NewLine +
				MessageString.ActualPrefix   + "\"Value\"" + MessageString.NewLine;
			
			StringAssert.isEmpty( "Value" );
		}
		
		[Test]
		[ExpectedError("funit.errors::AssertionError")]
		public function isEmptyFailureOnNull() : void
		{
			expectedMessage =
				MessageString.ExpectedPrefix + "<empty>" + MessageString.NewLine +
				MessageString.ActualPrefix   + "null"    + MessageString.NewLine;
			
			StringAssert.isEmpty( null );
		}
		
		[Test]
		public function isNotEmpty() : void
		{
			StringAssert.isNotEmpty( "Value", "Failed on String" );
		}
		
		[Test]
		[ExpectedError("funit.errors::AssertionError")]
		public function isNotEmptyFailureOnEmpty() : void
		{
			expectedMessage =
				MessageString.ExpectedPrefix + "not <empty>"    + MessageString.NewLine +
				MessageString.ActualPrefix   + "<empty>" + MessageString.NewLine;
			
			StringAssert.isNotEmpty( "" );
		}
		
		[Test]
		public function contains() : void
		{
			StringAssert.contains( "abc", "abc" );
			StringAssert.contains( "abc", "abc***" );
			StringAssert.contains( "abc", "***abc" );
			StringAssert.contains( "abc", "**abc**" );
		}
		
		[Test]
		[ExpectedError("funit.errors::AssertionError")]
		public function containsFailure() : void
		{
			expectedMessage =
				"  Expected: String containing \"abc\"" + MessageString.NewLine +
				"  But was:  \"ab*cd*ef\"" + MessageString.NewLine;
			
			StringAssert.contains("abc", "ab*cd*ef");
		}
		
		[Test]
		public function startsWith() : void
		{
			StringAssert.startsWith( "abc", "abc" );
			StringAssert.startsWith( "abc", "abcdef" );
		}
		
		[Test]
		[ExpectedError("funit.errors::AssertionError")]
		public function startsWithFailure() : void
		{
			expectedMessage =
				"  Expected: String starting with \"xyz\"" + MessageString.NewLine +
				"  But was:  \"abcxyz\"" + MessageString.NewLine;
			
			StringAssert.startsWith("xyz", "abcxyz");
		}
		
		[Test]
		public function endsWith() : void
		{
			StringAssert.endsWith( "xyz", "xyz" );
			StringAssert.endsWith( "xyz", "abcxyz" );
		}
		
		[Test]
		[ExpectedError("funit.errors::AssertionError")]
		public function endsWithFailure() : void
		{
			expectedMessage =
				"  Expected: String ending with \"xyz\"" + MessageString.NewLine +
				"  But was:  \"abcdef\"" + MessageString.NewLine;
			
			StringAssert.endsWith( "xyz", "abcdef" );
		}
		
		[Test]
		public function equalIgnoringCase() : void
		{
			StringAssert.areEqualIgnoringCase( "name", "NAME" );
		}
		
		[Test]
		[ExpectedError("funit.errors::AssertionError")]
		public function equalIgnoringCaseFailure() : void
		{
			expectedMessage =
				"  Expected string length 4 but was 8. Strings differ at index 0." + MessageString.NewLine +
				"  Expected: \"Name\", ignoring case" + MessageString.NewLine +
				"  But was:  \"LASTNAME\"" + MessageString.NewLine +
				"  -----------^" + MessageString.NewLine;
			
			StringAssert.areEqualIgnoringCase("Name", "LASTNAME");
		}
		
		[Test]
		[ExpectedError("funit.errors::AssertionError")]
		public function equalIgnoringCaseFailure2() : void
		{
			expectedMessage =
				"  Expected string length 4 but was 5. Strings differ at index 4." + MessageString.NewLine +
				"  Expected: \"Name\", ignoring case" + MessageString.NewLine +
				"  But was:  \"NAMES\"" + MessageString.NewLine +
				"  ---------------^" + MessageString.NewLine;
			
			StringAssert.areEqualIgnoringCase("Name", "NAMES");
		}
		
		[Test]		
		public function isMatch() : void
		{
			StringAssert.isMatch( "a?bc", "12a3bc45" );
		}
		
		[Test]
		[ExpectedError("funit.errors::AssertionError")]
		public function isMatchFailure() : void
		{
			expectedMessage =
				"  Expected: String matching \"a?b*c\"" + MessageString.NewLine +
				"  But was:  \"12ab456\"" + MessageString.NewLine;
			
			StringAssert.isMatch("a?b*c", "12ab456");
		}
		
	}
	
}